package com.itboye.ihomebank.base;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.Notification;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.os.Handler;
import android.support.multidex.MultiDexApplication;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.RemoteViews;
import android.widget.Toast;

import com.alibaba.mobileim.YWAPI;
import com.alibaba.wxlib.util.SysUtil;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.toolbox.Volley;
import com.baidu.mapapi.SDKInitializer;
import com.google.gson.Gson;
import com.itboye.ihomebank.R;
import com.itboye.ihomebank.activity.finance.HuanKuanActivity;
import com.itboye.ihomebank.activity.finance.HuanKuanDetailActivity;
import com.itboye.ihomebank.activity.finance.JieKuanRecordActivity;
import com.itboye.ihomebank.activity.home.ActivityXuanZuKe;
import com.itboye.ihomebank.activity.login.LoginActivity;
import com.itboye.ihomebank.activity.message.ActivitySystemMessage;
import com.itboye.ihomebank.activity.myzhujia.ActivityMyWallte;
import com.itboye.ihomebank.activity.qianyue.ActivityMySign;
import com.itboye.ihomebank.activity.qianyue.fragment.OrderFragment;
import com.itboye.ihomebank.bean.FJD;
import com.itboye.ihomebank.bean.NotificationBean;
import com.itboye.ihomebank.bean.RedDotBean;
import com.itboye.ihomebank.bean.ResultEntity;
import com.itboye.ihomebank.constants.SPContants;
import com.itboye.ihomebank.presenter.HousePresenter;
import com.itboye.ihomebank.presenter.UserPresenter;
import com.itboye.ihomebank.util.ByAlert;
import com.itboye.ihomebank.util.CrashHandler;
import com.itboye.ihomebank.util.ListDialog;
import com.itboye.ihomebank.util.SPUtils;
import com.itboye.ihomebank.util.broad.BroadEnum;
import com.itboye.ihomebank.util.controller.LoginController;
import com.itboye.ihomebank.util.controller.UnLoginState;
import com.itboye.ihomebank.zjtlcb.lnd.livenessdetector.utils.MD5Util;
import com.orhanobut.logger.Logger;
import com.sitri.sdk.SLock;
import com.umeng.message.IUmengRegisterCallback;
import com.umeng.message.PushAgent;
import com.umeng.message.UTrack;
import com.umeng.message.UmengMessageHandler;
import com.umeng.message.UmengNotificationClickHandler;
import com.umeng.message.entity.UMessage;

import org.json.JSONObject;

import java.lang.ref.WeakReference;
import java.security.SecureRandom;
import java.security.cert.X509Certificate;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import java.util.Observable;
import java.util.Observer;

import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSession;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;

import static com.itboye.ihomebank.base.BaseOtherActivity.EVENT_TYPE_UNKNOWN;

public class MyApplcation extends MultiDexApplication implements Observer {
    public static MyApplcation ctx;
    private Toast toast;
    private List<WeakReference<Activity>> activityList = new LinkedList<>();
    protected String afterOpen;
    protected String activity;
    protected String extra;
    protected org.json.JSONObject jsonObject2;
    protected String afterOpen2;
    protected String order_code;
    protected String id;
    protected int type;
    protected JSONObject jsonObject;
    boolean isReadOne, isReadTwo;
    public PushAgent mPushAgent;
    public HuanKuanDetailActivity HuanKuanDetailUI;
    public HuanKuanActivity huanKuanUI;
    public JieKuanRecordActivity jieKuanRecordUI;
    public static Activity curActivity;
    private static RequestQueue queue;
    private AppLifeCycle mAppLifeCycle;
    HousePresenter mHousePresenter;
    UserPresenter userPresenter;
//    public static RxDialogOne dialogOne;
    public static String device_token;
    public static ArrayList<String> list=new ArrayList<>();
    public static ListDialog mShenQin,mQianDing,mFujian,mYuQi;
    public static boolean isAlert=false;
    public PushAgent getmPushAgent() {
        return mPushAgent;
    }

    public static MyApplcation getInstance() {
        return ctx;
    }

//    https://fcloud.zjtlcb.com/sdk/app/ 以前的
    public String requestURL = "https://fcloud.zjtlcb.com/sdk/app/";//正式的 生产环境
//    public String requestURL = "https://221.12.107.165/sdkSIT/app/";//金融云后台地址 测试环境
//    public String requestURL = "https://221.12.107.165/sdk/zjjr/";  //回归环境

    public String requestCode1 = "approveDev";//开发者请求报文
    public String requestCode2 = "faceRecognition";//人脸识别成功后接口请求报文
    public String requestCode3 = "liveAndFaceRcgnt";//判断人脸识别是否为同一人接口请求报文
    public String isSamePerson = "fasle";//判断人脸识别是否为同一人


    //活体检测泰隆
    public String randomNum = (int)((Math.random()*9+1)*1000000)+"";

    public String appSecretKey = "76667510-c093-4b47-bacf-192d0502b9d4";//APP秘钥对应key
    public String appID = "5a9b7643_f8fa_4531_ae78_49980f1fe1a7";//APP秘钥


    public String encryptMethod = "AES";//加密方法
    public String seqNO = "0d39c71fbd2b490995b09664eb2e55b3";//序列号
    public String sign = MD5Util.MD5(randomNum + seqNO + appSecretKey);//APP签名
    public String signMethod = "MD5";//签名加密方法

    //head
    public String bussSeqNo = "";// 银行业务编号-入参，必填
    public String mrchSno = "";//商户业务编号-入参
    public String productId = "a43531ca990c4fde8e357792b9a4ba58";//产品ID
    public long sysTime = System.currentTimeMillis();
    public String txSno = sysTime+"";//交易流水号-时间戳
    SimpleDateFormat sdf=new SimpleDateFormat("yyyyMMddHHmmssSSS");
    public String txTime = sdf.format(new Date(Long.parseLong(String.valueOf(sysTime))));//交易时间
    //body
    public String storeAddress ="2201";//
    public String modelCode ="FCP";//
    public String sceneType ="02";//人脸识别场景：00:只做人脸识别；01:只做活体检测；02:人脸识别+活体检测

    private int ERRCount = 0;//识别错误次数

    public void setBussSeqNo(String bussSeqNo) {
        this.bussSeqNo = bussSeqNo;
    }

    public String getBussSeqNo() {
        return bussSeqNo;
    }

    public void setERRCount(int ERRCount) {
        this.ERRCount = ERRCount;
    }

    public int getERRCount() {
        return ERRCount;
    }


    public String getIsSamePerson() {
        return isSamePerson;
    }

    public void setIsSamePerson(String isSamePerson) {
        this.isSamePerson = isSamePerson;
    }

    public static void handleSSLHandshake() {
        try {
            TrustManager[] trustAllCerts = new TrustManager[]{
                    new X509TrustManager() {
                        public X509Certificate[] getAcceptedIssuers() {
                            return new X509Certificate[0];
    }
    @Override
    public void checkClientTrusted(X509Certificate[] certs, String authType) { }
    @Override
    public void checkServerTrusted(X509Certificate[] certs, String authType) { } }};

        SSLContext sc = SSLContext.getInstance("SSL");
        sc.init(null, trustAllCerts, new SecureRandom());
        HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
        HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() {
            @Override
        public boolean verify(String hostname, SSLSession session) { return true;
        } });
    } catch (Exception ignored) { } }

    @Override
    public void onCreate() {
        // TODO Auto-generated method stub
        super.onCreate();
        ctx = this;


        Logger.init("request_params");
        //初始化异常捕获类 CrashHandler
        CrashHandler.getInstance().init(this);

        TelephonyManager mTelephonyMgr = (TelephonyManager)MyApplcation.ctx.getSystemService(Context.TELEPHONY_SERVICE);
//            String imsi = mTelephonyMgr.getSubscriberId(); //获取IMSI号
        device_token= mTelephonyMgr.getDeviceId(); //获取IMEI号
        list.add(device_token);
        initUMengPush();
        queue = Volley.newRequestQueue(ctx);
        handleSSLHandshake();
        if (mustRunFirstInsideApplicationOnCreate()) {
            // todo 如果在":TCMSSevice"进程中，无需进行openIM和app业务的初始化，以节省内存
            return;
        }
        SDKInitializer.initialize(getApplicationContext());

        // 初始化云旺SDK
        initWXSDK();

        //初始化白马门锁
        SLock.getServices().init(this, "zhujiazulinclient", "zhujiazulinclient");

        //在Application中，注册监听 (app 由后台切换到前台时或启动后 弹框弹出 )
                mAppLifeCycle = new AppLifeCycle();
        registerActivityLifecycleCallbacks(mAppLifeCycle);  // 注册监听


        //泰隆
        setERRCount(0);
        setBussSeqNo("");
        setIsSamePerson("false");

        //app重启登录账户后或由后台转前台时的broadcast
        IntentFilter appIntentFilter=new IntentFilter(BroadEnum.APP_START_TanKuang);
        registerReceiver(appRestartedBroadcast,appIntentFilter);
//        //注册接受登录的广播
//        registerReceiver(loginReceiver,new IntentFilter("login_tankuang"));
        mHousePresenter=new HousePresenter(this);
        userPresenter= new UserPresenter(this);


    }
    //app重启或由后台转前台时的broadcast
    BroadcastReceiver appRestartedBroadcast =new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {

            if(!"".equals(SPUtils.get(ctx,null,SPContants.USER_ID,"")+"")){
                mHousePresenter.queryRedDot(SPUtils.get(ctx,null,SPContants.USER_ID,"")+"",device_token);
            }
            Log.d("====device==",device_token);
            Log.d("====uid==",SPUtils.get(ctx,null,SPContants.USER_ID,"")+"");

        }
    };
    //初始化openIM
    public void initWXSDK(){
//必须首先执行这部分代码, 如果在":TCMSSevice"进程中，无需进行云旺（OpenIM）和app业务的初始化，以节省内存;
        SysUtil.setApplication(this);
        if(SysUtil.isTCMSServiceProcess(this)){
            return;
        }
//第一个参数是Application Context
//这里的Const.OPEN_APPKEY即应用创建时申请的APP_KEY，同时初始化必须是在主进程中
        if(SysUtil.isMainProcess()){
            YWAPI.init(this, SPContants.YW_APPKEY);
        }


    }




    private void initUMengPush() {
        mPushAgent = PushAgent.getInstance(this);
        mPushAgent.setDebugMode(true);
        UmengMessageHandler messageHandler = new UmengMessageHandler() {
            /**
             * 自定义消息的回调方法
             * */
            @Override
            public void dealWithCustomMessage(final Context context,
                                              final UMessage msg) {
                new Handler().post(new Runnable() {

                    @Override
                    public void run() {
                        // TODO Auto-generated method stub
                        // 对自定义消息的处理方式，点击或者忽略
                        boolean isClickOrDismissed = true;
                        if (isClickOrDismissed) {
                            // 自定义消息的点击统计
                            UTrack.getInstance(getApplicationContext())
                                    .trackMsgClick(msg);
                        } else {
                            // 自定义消息的忽略统计
                            UTrack.getInstance(getApplicationContext())
                                    .trackMsgDismissed(msg);
                        }
                        Toast.makeText(context, msg.custom, Toast.LENGTH_LONG)
                                .show();
                    }
                });
            }

            @Override
            public void dealWithNotificationMessage(Context arg0, UMessage arg1) {
                // TODO Auto-generated method stub
                super.dealWithNotificationMessage(arg0, arg1);
                Gson gson = new Gson();
                NotificationBean bean = gson.fromJson(arg1.getRaw().toString(),
                        NotificationBean.class);
                Log.d("notification==",bean.toString());
                System.out.println("通知栏消息" + arg1.getRaw());
                isAlert=true;//判断是否有新的弹框 防止弹框多次弹出
                if (bean.getBody().getActivity()
                        .equals("contract_message")) {
                    Intent intent = new Intent(OrderFragment.REFRESH);
                    sendBroadcast(intent);
                }
                Intent intent = new Intent(BroadEnum.TanKuangType);
                Bundle bundle = new Bundle();



                //测试：现在看返回的text是什么。可以在接口自己定义

                if (bean.getBody().getActivity().equals("新设备登录消息")){
                    bundle.putString("type",BroadEnum.newDevice);
                    bundle.putString("contract_no","");
                    bundle.putString("content",bean.getBody().getText());
                }else
//                if (bean.getBody().getActivity().equals("rent_message")) {   //租客申请签约，经纪人选择租客弹框
//                    bundle.putString("type",BroadEnum.ZuKeShenQing);
//                    bundle.putString("contract_no","");
//                    bundle.putString("content",bean.getBody().getText());
//                } else
                if (bean.getExtra().getType().equals("contract_overdue")) {   //租客到期支付租金
                        bundle.putString("type",BroadEnum.ZhiFuZuJin);
                        bundle.putString("contract_no",bean.getExtra().getContract_no());
                        bundle.putString("content",bean.getBody().getText());
                 }else
                    if (bean.getExtra().getType().equals("contract_owner_written")) {   //经纪人填好合同，租客打开APP弹出，去签订合同

                    bundle.putString("type",BroadEnum.JingJiRenTianXie);
                    bundle.putString("contract_no",bean.getExtra().getContract_no());
                    bundle.putString("content",bean.getBody().getText());

                } else if (bean.getExtra().getType().equals("contract_facility_need_confirm")) {   //经纪人填写好附件单后，租客弹出确认
                        bundle.putString("type",BroadEnum.FuJianDan);
                        bundle.putString("contract_no",bean.getExtra().getContract_no());
                        bundle.putString("content",getStringContent(bean.getExtra()));
                }
                intent.putExtras(bundle);
                sendBroadcast(intent);

            }

            /**
             * 自定义通知栏样式的回调方法
             * */
            @SuppressLint("NewApi")
            @Override
            public Notification getNotification(Context context, UMessage msg) {
                switch (msg.builder_id) {
                    case 1:
                        Notification.Builder builder = new Notification.Builder(
                                context);
                        RemoteViews myNotificationView = new RemoteViews(
                                context.getPackageName(),
                                R.layout.notification_view);
                        myNotificationView.setTextViewText(R.id.notification_title,
                                msg.title);
                        myNotificationView.setTextViewText(R.id.notification_text,
                                msg.text);
                        myNotificationView.setImageViewBitmap(
                                R.id.notification_large_icon,
                                getLargeIcon(context, msg));
                        myNotificationView.setImageViewResource(
                                R.id.notification_small_icon,
                                getSmallIconId(context, msg));
                        builder.setContent(myNotificationView)
                                .setSmallIcon(getSmallIconId(context, msg))
                                .setTicker(msg.ticker).setAutoCancel(true);

                        return builder.getNotification();
                    default:
                        // 默认为0，若填写的builder_id并不存在，也使用默认。
                        return super.getNotification(context, msg);
                }
            }
        };
        mPushAgent.setMessageHandler(messageHandler);

        /**
         * 自定义行为的回调处理 UmengNotificationClickHandler是在BroadcastReceiver中被调用，故
         * 如果需启动Activity，需添加Intent.FLAG_ACTIVITY_NEW_TASK
         * */
        UmengNotificationClickHandler notificationClickHandler = new UmengNotificationClickHandler() {
            @Override
            public void dealWithCustomAction(Context context, UMessage msg) {

            }

            @Override
            public void openActivity(Context arg0, UMessage arg1) {
                // TODO Auto-generated method stub
                // super.openActivity(arg0, arg1);//必须注释掉才能执行指定类的跳转
                Gson gson = new Gson();
                NotificationBean bean = gson.fromJson(arg1.getRaw().toString(),
                        NotificationBean.class);
                Intent intent = new Intent();
                Log.d("openActivity==",bean.toString());
                String uid = SPUtils.get(ctx, null, SPContants.USER_ID, "")
                        + "";
                if (uid.equals("")) {
                    intent = new Intent(ctx, LoginActivity.class);
                    startActivity(intent);
                    return;
                }
                if (bean.getBody().getActivity().equals("system_message")) {
                    intent = new Intent(ctx, ActivitySystemMessage.class);
                    intent.putExtra("type", 1);
                } else if (bean.getBody().getActivity()
                        .equals("contract_message")) {
                    intent = new Intent(ctx, ActivityMySign.class);
                    // intent.putExtra("contract_no", bean.getFJD().getId());
                    // Intent intent1 = new Intent(OrderFragment.REFRESH);
                    sendBroadcast(intent);
                } else if (bean.getBody().getActivity().equals("lock_message")) {
                    intent = new Intent(ctx, ActivitySystemMessage.class);
                    intent.putExtra("type", 4);
                } else if (bean.getBody().getActivity().equals("wallet_message")) {
                    intent = new Intent(ctx, ActivityMyWallte.class);
                    intent.putExtra("type", 5);
                } else if (bean.getBody().getActivity().equals("rent_message")) {
                    //intent = new Intent(ctx, WodeFangyuanActivity.class);
                    intent = new Intent(ctx, ActivityXuanZuKe.class);
                    intent.putExtra("house_no", bean.getExtra().getContract_no());
                }else if (bean.getBody().getActivity().equals("go_activity")){
                    LoginController.setLoginState(new UnLoginState  ());
                    intent = new Intent(ctx,LoginActivity.class);
                }
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                startActivity(intent);
            }
        };
//         使用自定义的NotificationHandler，来结合友盟统计处理消息通知
//         参考http://bbs.umeng.com/thread-11112-1-1.html
//         CustomNotificationHandler notificationClickHandler = new
//         CustomNotificationHandler();

        mPushAgent.setNotificationClickHandler(notificationClickHandler);

        // 注册推送服务 每次调用register都会回调该接口
        mPushAgent.register(new IUmengRegisterCallback() {
            @Override
            public void onSuccess(String deviceToken) {
                System.out.println(">>>" + deviceToken);
                Log.d("====devicetoken===",deviceToken);
            }

            @Override
            public void onFailure(String s, String s1) {

            }
        });

    }



    private boolean mustRunFirstInsideApplicationOnCreate() {
        // 必须的初始化
        SysUtil.setApplication(this);
        return SysUtil.isTCMSServiceProcess(getApplicationContext());
    }

    public void showNetWorkError() {
        if (toast == null) {
            toast = Toast.makeText(MyApplcation.ctx, "", Toast.LENGTH_LONG);
            toast.setGravity(Gravity.CENTER, 0, 0);
            toast.setView(LayoutInflater.from(MyApplcation.ctx).inflate(
                    R.layout.dialog_network_error, null));
        }

        toast.show();
    }

    public void addActivity(Activity activity) {
        activityList.add(new WeakReference<Activity>(activity));
    }

    // 遍历所有Activity并finish
    public void exit() {
        for (WeakReference<Activity> activity : activityList) {
            if (activity.get() != null) {
                activity.get().finish();
            }

        }
        System.exit(0);
    }

    /**
     * @return the queue
     */
    public static RequestQueue getQueue() {
        return queue;
    }

    public static <T> void addRequest(Request<T> request) {
        request.addMarker("itboye");
        getQueue().add(request);
    }




    @Override
    public void update(Observable o, Object arg) {
        ResultEntity entity = handlerError(arg);
//        ByAlert.alert(entity.getMsg());
        if (entity != null) {
           if (entity.getEventType() == HousePresenter.queryRedDot_success){
                Log.d("hongdian=","true");
                RedDotBean mRedDotBean= (RedDotBean) entity.getData();
                showDialog(mRedDotBean);//展示所有弹框
//                saveRedDotData(mRedDotBean);//保存红点数据
            }else if (entity.getEventType() == HousePresenter.queryRedDot_fail){

            }else if (entity.getEventType() == UserPresenter.qingdan_success) {//租客确认附件单
               ByAlert.alert(entity.getData());
               sendBroadcast(new Intent("showRedDot"));
           } else  if (entity.getEventType() == UserPresenter.qingdan_fail){
               ByAlert.alert(entity.getData());
           }
        }
    }



    /**
     * @param data
     * @return 2016-4-23 hebidu
     */
    public ResultEntity handlerError(Object data) {
        ResultEntity result = (ResultEntity) data;
        if (result == null) {
            result = new ResultEntity("-1", "数据格式错误!~", data);
            return result;
        }

        if (result.hasError()) {
            //   ByAlert.alert(result.getMsg());
            if (result.getMsg().contains("java.net.UnknownHostException")) {
                ByAlert.alert("请连接网络 ");
            } else {
//                ByAlert.alert(result.getMsg());
            }
            result.setEventType(EVENT_TYPE_UNKNOWN);
            return result;
        }

        return result;
    }


//    //接受登陆后的广播
//    BroadcastReceiver loginReceiver=new BroadcastReceiver() {
//        @Override
//        public void onReceive(Context context, Intent intent) {
//            Log.d("====device==",device_token);
//            mHousePresenter.queryRedDot(SPUtils.get(ctx,null,SPContants.USER_ID,"")+"",device_token);
//        }
//    };
    //显示dialog
    private  void showDialog(RedDotBean mRedDotBean){
        //dialog type  1  尚有租金逾期未交  2 尚有附件清单未确认 3 尚有未完成的签约 4 尚有申请签约的房源

        if (mShenQin==null){
            //经纪人去选租客
            if (mRedDotBean.getApply_list().size()>0){
                mShenQin= new ListDialog(
                        curActivity,
                        "尚有申请签约的房源",
                        mRedDotBean.getApply_list(),
                        4);
                mShenQin.getDialog_cancelImg().setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        mShenQin.cancel();
                        mShenQin=null;
                    }
                });
                if (mRedDotBean.getApply_list().size()>12){
                    mShenQin.setListDialogHeigh();
                }
                mShenQin.show();
            }
        }

        if (mQianDing==null){
            //租客签订合同
            if (mRedDotBean.getNeed_sign_contract_list().size()>0){
                mQianDing= new ListDialog(
                        curActivity,
                        "尚有未完成的签约",
                        mRedDotBean.getNeed_sign_contract_list(),
                        3);

                mQianDing.getDialog_cancelImg().setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        mQianDing.cancel();
                        mQianDing=null;
                    }
                });
                if (mRedDotBean.getNeed_sign_contract_list().size()>12){
                    mQianDing.setListDialogHeigh();
                }
                mQianDing.show();
            }
        }

        if (mFujian==null){
            //租客确定附件单
            if (mRedDotBean.getNeed_confirm_facility_list().size()>0){
                List<String> confirm = new ArrayList<>();
                List<String> contract_no = new ArrayList<>();
                for (int i=0;i< mRedDotBean.getNeed_confirm_facility_list().size();i++){
                    contract_no.add(mRedDotBean.getNeed_confirm_facility_list().get(i).getContract_no());
                    confirm.add(getStringContent(mRedDotBean.getNeed_confirm_facility_list().get(i)));
                }
                mFujian= new ListDialog(
                        curActivity,
                        "尚有附件清单未确认",
                        confirm,
                        2,contract_no);
                mFujian.getDialog_cancelImg().setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        mFujian.cancel();
                        mFujian=null;
                    }
                });

                if (mRedDotBean.getNeed_confirm_facility_list().size()>2){
                    mFujian.setListDialogHeigh();
                }
                mFujian.show();
            }
        }
        if (mYuQi==null){

            //租客逾期支付
            if (mRedDotBean.getOverdue_list().size()>0){
                mYuQi= new ListDialog(
                        curActivity,
                        "尚有租金逾期未交",
                        mRedDotBean.getOverdue_list(),
                        1);
                mYuQi.getDialog_cancelImg().setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        mYuQi.cancel();
                        mYuQi=null;
                    }
                });
                if (mRedDotBean.getOverdue_list().size()>12){
                    mYuQi.setListDialogHeigh();
                }
                mYuQi.show();
            }
        }





    }

    //拼接字符串
    public static String getStringContent(FJD facility){

        return "您租用的"+facility.getAddress()+"\n"+"电表度数:"+facility.getElectric_instrument_reading()+"  燃气度数:"+facility.getGas_reading()+"  水表:"+facility.getWater_meter_reading()
                +"\n"+"设施清单:"+facility.getFacility();
    }

    public static class MyActivityManager {
        private static MyActivityManager sInstance = new MyActivityManager();
        // 采用弱引用持有 Activity ，避免造成 内存泄露
        private WeakReference<Activity> sCurrentActivityWeakRef;


        private MyActivityManager() {

        }

        public static MyActivityManager getInstance() {
            return sInstance;
        }

        public Activity getCurrentActivity() {
            Activity currentActivity = null;
            if (sCurrentActivityWeakRef != null) {
                currentActivity = sCurrentActivityWeakRef.get();
            }
            return currentActivity;
        }

        public void setCurrentActivity(Activity activity) {
            sCurrentActivityWeakRef = new WeakReference<Activity>(activity);
        }


    }

}
